<template>
  <!-- 新增|刷新 -->
  <div class="flex items-center justify-between mb-4">
    <div>
      <el-button
        type="primary"
        size="small"
        v-if="btns.includes('create')"
        @click="$emit('create')"
      >
        新增
      </el-button>

      <el-popconfirm
        title="是否要删除选中记录?"
        confirm-button-text="确认"
        cancel-button-text="取消"
        v-if="btns.includes('delete')"
        @confirm="$emit('delete')"
      >
        <template #reference>
          <el-button
            type="danger"
            size="small"
          >
            批量删除
          </el-button>
        </template>
      </el-popconfirm>

      <!-- 上架/下架 -->
      <slot />
    </div>

    <div>
      <el-tooltip
        effect="dark"
        content="刷新数据"
        placement="top"
        v-if="btns.includes('refresh')"
      >
        <el-button
          @click="$emit('refresh')"
          text
          size="small"
        >
          <el-icon :size="15">
            <Refresh />
          </el-icon>
        </el-button>
      </el-tooltip>

      <el-tooltip
        effect="dark"
        content="导出数据"
        placement="top"
        v-if="btns.includes('download')"
      >
        <el-button
          @click="$emit('download')"
          text
          size="small"
        >
          <el-icon :size="15">
            <Download />
          </el-icon>
        </el-button>
      </el-tooltip>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue";

const props = defineProps({
  layout: {
    type: String,
    default: "create,refresh",
  },
});

const btns = computed(() => props.layout.split(","));

defineEmits(["create", "refresh", "delete", "download"]);
</script>
